package com.cljz.makepassenger.ui.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;

import com.cljz.makepassenger.R;
import com.cljz.makepassenger.model.net.bean.InvitationBean;
import com.cljz.makepassenger.ui.holder.LetterBgHolder;

import java.util.List;

/**
 * Created by apple on 2017/4/10.
 */

public class LetterBgPicAdapter extends RecyclerView.Adapter<LetterBgHolder> {
    private Context context;
    private OnItemClickListener mOnItemClickListener;
    private List<InvitationBean.DataBean> invitations;
    private String mSelect = "";


    public LetterBgPicAdapter(Context context, List<InvitationBean.DataBean> invitations) {
        this.context = context;
        this.invitations = invitations;
    }

    @Override
    public LetterBgHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new LetterBgHolder(View.inflate(context, R.layout.item_bg_pic, null));
    }

    @Override
    public void onBindViewHolder(LetterBgHolder holder, final int position) {
        holder.setData(invitations, position, mSelect);
        if (mOnItemClickListener != null) {
            holder.itemView.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    mOnItemClickListener.onClick(invitations.get(position));
                }
            });

            holder.itemView.setOnLongClickListener(new View.OnLongClickListener() {
                @Override
                public boolean onLongClick(View v) {
                    mOnItemClickListener.onLongClick(invitations.get(position));
                    return false;
                }
            });
        }
    }

    @Override
    public int getItemCount() {
        return invitations == null ? 0 : invitations.size();
    }

    public void changeSelected(String id) {
        if (!mSelect.equals(id)) {
            mSelect = id;
            notifyDataSetChanged();
        }
    }

    public void setData(List<InvitationBean.DataBean> dataBeen) {
        invitations = dataBeen;
        notifyDataSetChanged();
    }

    public interface OnItemClickListener {
        void onClick(InvitationBean.DataBean dataBean);

        void onLongClick(InvitationBean.DataBean dataBean);
    }

    public void setOnItemClickListener(OnItemClickListener onItemClickListener) {
        this.mOnItemClickListener = onItemClickListener;
    }


}
